package org.litespring.core.io;

import org.litespring.util.Assert;
import org.litespring.util.ClassUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class FileSystemResource implements Resource {
    private String path;
    private File file;

    public FileSystemResource(String config) {
        Assert.notNull(config,"Path must not be null");
        this.path = config;
        this.file = new File(path);
    }

    @Override
    public InputStream getInputStream() throws FileNotFoundException {
        InputStream is = new FileInputStream(file);
        if (is == null) {
            throw new FileNotFoundException(path + "cannot be opened");
        }
        return is;
    }
}
